//
//  ViewController.m
//  ChartDemoX
//
//  Created by yuanpt on 17/5/6.
//  Copyright © 2017年 yuanpt. All rights reserved.
//

#import "ViewController.h"
#import "ChartLine.h"
#import "ChartView.h"
#import "ChartXAxisView.h"
#import "ChartYAxisView.h"
#import "ChartDrawView.h"
#import "UIView+Extension.h"
#import "ChartUtil.h"




// Y
//@property (nonatomic, copy) NSString *yAxisTitle;
//@property (nonatomic, strong) UILabel *yAxisTitleLabel;
//@property (nonatomic, strong) ChartYAxisView *yAxisView;


//    /**
//     y 轴最大值
//     */
//    @property (nonatomic, assign) CGFloat yMaxValue; // 120
//
//    /**
//     每个数之间有多少个格子
//     */
//    @property (nonatomic, assign) NSInteger yGridSplit; // 5
//
//    /**
//     坐标递增差值 10
//     */
//    @property (nonatomic, assign) CGFloat yGridValue; // 10
//
//
//    /**
//     y 轴最小值
//     */
//    @property (nonatomic, assign) CGFloat yMinValue; // 40


//    @property (nonatomic, copy) NSString *xAxisTitle;
//    @property (nonatomic, strong) UILabel *xAxisTitleLabel;
//    @property (nonatomic, strong) ChartXAxisView *xAxisView;
//
//    /**
//     有多少小格
//     */
//    @property (nonatomic, assign) NSInteger xGridSplit; // 4
//
//    /**
//     大格差值
//     */
//    @property (nonatomic, assign) CGFloat xGridValue;
//
//    /**
//     没个页，显示多少个 233
//     */
//    @property (nonatomic, assign) CGFloat xPerScreen; //6

@interface ViewController ()

@property (nonatomic, strong) ChartView *chartView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.view addSubview:self.chartView];
    self.chartView.yMaxValue = 120;
    self.chartView.yMinValue = 40;
    self.chartView.yGridSplit = 5;
    self.chartView.yGridValue = 10;
    self.chartView.yAxisTitle = @"身高（厘米）";
    
    self.chartView.xAxisTitle = @"宝宝月龄";
    self.chartView.xGridSplit = 4;
    self.chartView.xGridValue = 1;
    self.chartView.xPerScreen = 6;
    self.chartView.xMaxValue = 36;
//    self.chartView.backgroundColor = [UIColor redColor];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.chartView.drawView setNeedsDisplay];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.chartView.sy_size = CGSizeMake(320.0f  * scale(), 495.0f  * scale());
    self.chartView.center = self.view.sy_middle;
    
    ChartLine *normalLine = [[ChartLine alloc] init];
    
    normalLine.points = @[
                          [NSValue valueWithCGPoint:CGPointMake(0, 334)],
                          [NSValue valueWithCGPoint:CGPointMake(42, 312)],
                          [NSValue valueWithCGPoint:CGPointMake(85, 294)],
                          [NSValue valueWithCGPoint:CGPointMake(127, 278)],
                          [NSValue valueWithCGPoint:CGPointMake(170, 265)],
                          [NSValue valueWithCGPoint:CGPointMake(212, 255)],
                          [NSValue valueWithCGPoint:CGPointMake(255, 247)],
                          [NSValue valueWithCGPoint:CGPointMake(297, 240)],
                          [NSValue valueWithCGPoint:CGPointMake(340, 234)],
                          [NSValue valueWithCGPoint:CGPointMake(1530, 108)],
                          ];
    self.chartView.xToday = 85;
    
//    normalLine.points = @[
//                          [NSValue valueWithCGPoint:CGPointMake(0, 50)],
//                          [NSValue valueWithCGPoint:CGPointMake(1, 55)],
//                          [NSValue valueWithCGPoint:CGPointMake(2, 60)],
//                          [NSValue valueWithCGPoint:CGPointMake(3, 65)],
//                          [NSValue valueWithCGPoint:CGPointMake(4, 70)],
//                          [NSValue valueWithCGPoint:CGPointMake(5, 75)],
//                          [NSValue valueWithCGPoint:CGPointMake(6, 80)],
//                          [NSValue valueWithCGPoint:CGPointMake(7, 85)],
//                          [NSValue valueWithCGPoint:CGPointMake(8, 90)],
//                          [NSValue valueWithCGPoint:CGPointMake(36, 120)],
//                          ];
    
    
    ChartLine *minLine = [[ChartLine alloc] init];
    
    minLine.points = @[
                       [NSValue valueWithCGPoint:CGPointMake(0, 350)],
                       [NSValue valueWithCGPoint:CGPointMake(42, 332)],
                       [NSValue valueWithCGPoint:CGPointMake(85, 315)],
                       [NSValue valueWithCGPoint:CGPointMake(127, 300)],
                       [NSValue valueWithCGPoint:CGPointMake(170, 287)],
                       [NSValue valueWithCGPoint:CGPointMake(212, 277)],
                       [NSValue valueWithCGPoint:CGPointMake(255, 270)],
                       [NSValue valueWithCGPoint:CGPointMake(297, 264)],
                       [NSValue valueWithCGPoint:CGPointMake(340, 257)],
                       [NSValue valueWithCGPoint:CGPointMake(1530, 144)],
                       ];

    
//    minLine.points = @[
//                          [NSValue valueWithCGPoint:CGPointMake(0, 45)],
//                          [NSValue valueWithCGPoint:CGPointMake(1, 55 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(2, 60 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(3, 65 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(4, 70 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(5, 75 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(6, 80 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(7, 85 - 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(8, 90 -5 )],
//                          [NSValue valueWithCGPoint:CGPointMake(36, 120 -5)],
//                          ];
    
    ChartLine *maxLine = [[ChartLine alloc] init];
    
    maxLine.points = @[
                       [NSValue valueWithCGPoint:CGPointMake(0, 316)],
                       [NSValue valueWithCGPoint:CGPointMake(42, 292)],
                       [NSValue valueWithCGPoint:CGPointMake(85, 272)],
                       [NSValue valueWithCGPoint:CGPointMake(127, 256)],
                       [NSValue valueWithCGPoint:CGPointMake(170, 243)],
                       [NSValue valueWithCGPoint:CGPointMake(212, 232)],
                       [NSValue valueWithCGPoint:CGPointMake(255, 224)],
                       [NSValue valueWithCGPoint:CGPointMake(297, 216)],
                       [NSValue valueWithCGPoint:CGPointMake(340, 209)],
                       [NSValue valueWithCGPoint:CGPointMake(1530, 70)],
                       ];
    
//    maxLine.points = @[
//                          [NSValue valueWithCGPoint:CGPointMake(0, 50 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(1, 55 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(2, 60 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(3, 65 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(4, 70 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(5, 75 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(6, 80 +5)],
//                          [NSValue valueWithCGPoint:CGPointMake(7, 85+ 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(8, 90 + 5)],
//                          [NSValue valueWithCGPoint:CGPointMake(36, 120 + 5)],
//                          ];
    
    
    ChartLine *recLine = [[ChartLine alloc] init];
    
    
    
    recLine.points = @[
                       [NSValue valueWithCGPoint:CGPointMake(0, 334 - 10)],
                       [NSValue valueWithCGPoint:CGPointMake(42, 312 - 20)],
                       [NSValue valueWithCGPoint:CGPointMake(85, 294 - 30)],
                       [NSValue valueWithCGPoint:CGPointMake(127, 278 - 40)],
                       [NSValue valueWithCGPoint:CGPointMake(170, 265 - 10)],
                       [NSValue valueWithCGPoint:CGPointMake(212, 255 - 101)],
                       [NSValue valueWithCGPoint:CGPointMake(255, 247 - 60)],
                       [NSValue valueWithCGPoint:CGPointMake(297, 240 - 10)],
                       [NSValue valueWithCGPoint:CGPointMake(340, 234 - 90)],
                       [NSValue valueWithCGPoint:CGPointMake(1530, 108 - 10)],
                       ];
    
    self.chartView.normalLine = normalLine;
    self.chartView.maxLine = maxLine;
    self.chartView.minLine = minLine;
    self.chartView.recordLine = recLine;
}

- (ChartView *)chartView {
    if (!_chartView) {
        _chartView = [[ChartView alloc] init];
    }
    return _chartView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
